layui.extend({
	authMock: "mock/auth",
}).define(["authMock", "BaseServices", "apiAuth", "MD5", "utils"], function (exports) {
	var MD5 = layui.MD5,
		BaseServices = layui.BaseServices,
		authMock = layui.authMock,
		apiModule = layui.apiAuth,
		utils = layui.utils;
	authMock();

	function AuthServices(apiModule) {
		BaseServices.apply(this, arguments);
	}

	utils.inheritPrototype(AuthServices, BaseServices);

	/**
	 * @author: ares
	 * @date: 2020/2/2 19:55
	 * @description: 登录
	 * @param {string}username
	 * @param {string}password
	 * @param {string}code
	 */
	AuthServices.prototype.login = function (username, password, code) {
		var params = {
			username: username,
			password: password,
			// password: MD5.hex_md5(password + "{cloud}"),
			code: code
		};
		return this.service(this.apiModule.api.login, {params: params});
	}
	/**
	 * @author: ares
	 * @date: 2020/2/2 19:56
	 * @description: 退出登录
	 */
	AuthServices.prototype.logout = function () {
		return this.service(this.apiModule.api.logout, {method: "delete"}).then(function (res) {
			top.location.replace("index.html");
		});
	}
	/**
	 * @author: ares
	 * @date: 2020/12/15 10:35
	 * @description: 修改密码
	 * @param {string}oldPwd  旧密码
	 * @param {string}newPwd  新密码
	 * @returns {Promise.<TResult>|*}
	 */
	AuthServices.prototype.modifyPwd = function (oldPwd, newPwd) {
		var params = {
			oldPwd: oldPwd,
			newPwd: newPwd,
			// pwd: MD5.hex_md5(pwd + "{cloud}"),
			// new_pwd: MD5.hex_md5(new_pwd + "{cloud}"),
		};
		return this.service(this.apiModule.api.modifyPwd, {method: "put", params: params});
	}

	exports("authServices", new AuthServices(apiModule));
});
